package config

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"os"
)

type Cfg struct {
	Server  ServerCfg
	Redis   RedisCfg
	MongoDB MongoDBCfg
	Mysql   MysqlCfg
}
type ServerCfg struct {
	Port string
}
type RedisCfg struct {
	Addr     string
	Password string
	DB       int
}
type MongoDBCfg struct {
	Addr        string
	DB          string
	MinPoolSize int
	MaxPoolSize int
	TimeOut     int
}
type MysqlCfg struct {
	Username     string
	Password     string
	Addr         string
	DB           string
	MaxIdleConns int
	MaxOpenConns int
}

func Init() Cfg {
	file, err := os.Open("config/cfg.yaml")
	if err != nil {
		panic(err)
	}
	bytes, err := ioutil.ReadAll(file)
	if err != nil {
		panic(err)
	}
	cfg := Cfg{}
	err = yaml.Unmarshal(bytes, &cfg)
	if err != nil {
		panic(err)
	}
	return cfg
}
